package com.baizhi.serviceImpl;


import com.baizhi.dao.FeedbackDao;
import com.baizhi.entity.Feedback;
import com.baizhi.service.FeedbackService;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional
public class FeedbackServiceImpl extends ServiceImpl<FeedbackDao, Feedback> implements FeedbackService {

    @Autowired
    private FeedbackDao feedbackDao;

    /**
     * 分页查所有
     */
    @Override
    public HashMap<String, Object> pageQueryAll(Integer page,Integer pageSize) {
        HashMap<String, Object> map = new HashMap<>();
        map.put("page",page);
        Page<Feedback> pages = new Page<>(page,pageSize);
        Page<Feedback> selectPage = feedbackDao.selectPage(pages, null);
        long total = selectPage.getTotal();
        map.put("total",total);
        List<Feedback> records = selectPage.getRecords();
        map.put("rows",records);
        return map;
    }

    /**
     * 删除
     *
     * @param feedback
     */
    @Override
    public HashMap<String, Object> delete(Feedback feedback) {
        HashMap<String, Object> map = null;
        try {
            map = new HashMap<>();
            int i = feedbackDao.deleteById(feedback.getId());
            map.put("message","删除成功"+i+"条数据");
        } catch (Exception e) {
            e.printStackTrace();
            map.put("message","删除失败");
        }
        return map;
    }
}